// stores/counter.js
import { defineStore } from "pinia";

export const useUserStore = defineStore("user", {
  //需要维护的状态
  state: () => {
    return {
      isAutnenticated: false, // 是否认证
      user: {}, // 存储用户信息
    };
  },

  actions: {
    // 设置认证状态
    SET_IS_AUTNENTIATED(isAutnenticated) {
      if (isAutnenticated) this.isAutnenticated = isAutnenticated;
      else this.isAutnenticated = false;
    },
    //   设置用户信息
    SET_USER(user) {
      if (user) this.user = user;
      else this.user = {};
    },
    // 清空
    clearCurrentState() {
      this.isAutnenticated = false;
      this.user = {};
    },
  },

  getters: {
    getIsAutnenticated: (state) => state.isAutnenticated,
    getUser: (state) => state.user,
  },

  persist: {
    enabled: true, // 这个配置代表存储生效，而且是整个store都存储
  },
});
